//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _PLAYER_PARTICLEFACTORY_H
#define _PLAYER_PARTICLEFACTORY_H
//
#include <global.h>
#include <QtCore/QList>
#include <osg/Referenced>
#include <model/particletemplate.h>
#include <model/randomdouble.h>
#include "particleparam.h"
#include "particle_fwd.h"
#include "particlesystem_fwd.h"
#include "controller_fwd.h"
#include "emitter_fwd.h"
//
namespace player
{
class ParticleFactory:public osg::Referenced
{
//forbidden
private:
   ParticleFactory(const ParticleFactory&);
   ParticleFactory&operator=(const ParticleFactory&);
//structures
private:
   struct TimeMark
   {
      TimeMark(const model::RandomDouble &p_time,model::ParticleTemplate::TimeMark::Mode p_mode,int p_other);
      model::RandomDouble time;
      model::ParticleTemplate::TimeMark::Mode mode;
      int other;
   };
   struct EmitterBlock
   {
      EmitterBlock(int p_t_start,Emitter *p_emitter);
      EmitterBlock(int p_t_start,int p_t_end,double p_dt_min,double p_dt_max,Emitter *p_emitter);
      int t_start;
      int t_end;
      double dt_min;
      double dt_max;
      Emitter *emitter;
   };
//construction
public:
   ParticleFactory();
   ~ParticleFactory();
   void init_setup(Controller *p_controller,ParticleSystem *p_particle_system,const model::ParticleTemplate *p_particle_template);
//operation
public:
   Particle *create();
   void setup(Particle *p_particle,const ParticleParam&p_param);
private:
   void setup_time_marks();
//data
private:
   Controller *controller;
   const model::ParticleTemplate *particle_template;
   ParticleSystem *particle_system;
   QList<TimeMark> time_marks;
   QList<int> color_control_point_index;
   QList<int> alpha_control_point_index;
   QList<int> size_control_point_index;
   QList<int> mass_control_point_index;
   QList<EmitterBlock> emitter_blocks;
};
}
//
#endif
